﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;


namespace MapleLeaf.Client{
    public class PatchContext {


        public event PropertyChangedEventHandler PropertyChanged;


        public void PropertyChange(string name) {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }


        public ObservableCollection<PatchInfo> PatchList { get; }


        public string ProductName { get; }


        public string Message {
            get => _Message;
            set {
                _Message = value;
                PropertyChange("Message");
            }
        }

        public long PatchLength {
            get => _PatchLength;
            set {
                _PatchLength = value;
                PropertyChange("PatchLength");
                PropertyChange("Progress");
            }
        }
        public long PatchedLength {
            get => _PatchedLength;
            set {
                _PatchedLength = value;
                PropertyChange("_PatchedLength");
                PropertyChange("Progress");
            }
        }

        public double Progress => (PatchLength == 0L) ? 100.0 : (PatchedLength / (double)PatchLength * 100.0);


        public PatchContext(string productName) : base() {
            PatchList = new ObservableCollection<PatchInfo>();
            ProductName = productName;
        }

        private string _Message;
        private long _PatchLength;

        private long _PatchedLength;
    }
}
